<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 创建一个数组
        var num = [4, 3, 2, 7, 8, 2, 3, 1]
        //  取出最大值 并循环出数组arr
        var max = Math.max(...num)
        var arr = []
        for (var i = 1; i <= max; i++) {
            arr.push(i)
        }
        //  利用filter方法判断num数组中没有arr的数据并返回出新的数组res
        var res = arr.filter(function(items, indxt) {
            return num.indexOf(items) === -1
        })
        console.log(res)
    </script>
</body>

</html>